﻿using System;
using NUnit.Framework;
using System.Transactions;
using ProjetoComperio.BusinessLogicLayer;
using ProjetoComperio.DataLayer.Entities;
using ProjetoComperio.Framework.Web.Security;

namespace ProjetoComperio.Test.BusinessLogicLayer
{
    [TestFixture]
    public class StudentBLLTest
    {


        StudentBLL studentBLL;
        public static string UserName = "HigorCesar_1" + new Random().Next() * 10;
        [TestFixtureSetUp]
        public void SetUp()
        {
            studentBLL = new StudentBLL();

        }

        [Test]
        [ExpectedException(typeof(NullReferenceException))]
        public void TestCreateExpectsNullException()
        {
            studentBLL.Create(null, null, null);

        }

        [Test]
        [NUnit.Framework.Category("Lazy")]
        public void TestCreateStudentAndUser()
        {
            using (TransactionScope transactionScope = new TransactionScope())
            {

                Student student = CreateFakeStudent();
                String password = "1234ABCD_90s";
                studentBLL.Create(student, UserName, password);
                var user = new ComperioMemberShipProvider().RetrieveUser(UserName);
                Assert.AreNotEqual(0, student.PersonID);
                Assert.AreNotEqual(0, user.UserID);

                transactionScope.Dispose();
            }
        }

        public static Student CreateFakeStudent()
        {
            var student = new Student();
            student.AcademicOrganizationID = 1;
            student.AddressNumber = "180";
            student.BirthDate = new DateTime(1989, 8, 2);
            student.City = "Rio de Janeiro";
            student.Country = "Brasil";
            student.CourseID = 1;
            student.EducationLevelID = 1;
            student.Email = "hg@gmail.com" + new Random().Next() * 10; ;
            student.Enrollment = "1";
            student.LattesPlatformWebPage = "";
            student.Name = "HgTest";
            student.Neighbourhood = "Tg";
            student.StartDate = new DateTime(2008, 1, 1);
            student.State = "RJ";
            student.Street = "Tg";
            student.WebPage = "Wp";
            student.ZipCode = "21221";

            return student;
        }
    }

}
